package com.mttang.sys.integration.dao.support;

import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.ibatis.sqlmap.client.SqlMapException;
import com.mttang.framework.core.paginated.util.PagedFliper;
import com.mttang.framework.core.paginated.util.Sheet;
import com.mttang.sys.integration.dao.SystemLogDAO;

public class SystemLogDAOImpl extends SqlMapClientDaoSupport implements SystemLogDAO {
	
	 private Log logger = LogFactory.getLog(getClass());
	 
	 @Override
	public Sheet qryLog(PagedFliper fliper) {
		if (logger.isInfoEnabled()) {
            logger.info("进入 SystemLogDAOImpl.qryLog()");
        }
		
		Sheet datas = Sheet.EMPTY;
		try{
			int rowcount = (Integer)getSqlMapClientTemplate().queryForObject("SYS.qryCntSystemLog",fliper);
			// 设置记录数 (1)代码必须在(2)前 因为得到列表页面需要总记录数参数 
			fliper.setRecordCount(rowcount);
			List data = getSqlMapClientTemplate().queryForList("SYS.qrySystemLog", fliper);
			datas = new Sheet(rowcount,data);
			
			if (logger.isInfoEnabled()) {
	            logger.info("正常退出 SystemLogDAOImpl.qryLog()");
	        }
			
		}
		catch(SqlMapException ex){
			if (logger.isErrorEnabled()) {
	            logger.info("error:" + ex);
	        }
		}

		return datas;
	}
	 
	public boolean addLog(Map<Object, Object> vo){
		
		if (logger.isInfoEnabled()) {
            logger.info("进入  SystemLogDAOImpl.addLog()");
        }
		
		try{
			getSqlMapClientTemplate().insert("SYS.addSystemLog", vo);
			
			if (logger.isInfoEnabled()) {
	            logger.info("正常退出SystemLogDAOImpl.addLog()");
	        }
			
			return true;
		}
		catch(SqlMapException ex){
			if (logger.isErrorEnabled()) {
	            logger.info("error:" + ex);
	        }
			
			return false;
		}
	}

}
